﻿using Azure;
using MySqlX.XDevAPI;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace S7Simulate
{
    public partial class DeepSeekMain : Form
    {
        private static readonly HttpClient client = new HttpClient();
        public DeepSeekMain()
        {
            InitializeComponent();
        }

        private async void button1_Click(object sender, EventArgs e)
        {
            string apiKey = "sk-06008ce399f0425dac2c5346a3283bdf"; // 替换为你的DeepSeek API密钥
            string apiUrl = "https://api.deepseek.com/chat/completions"; // 替换为DeepSeek API的URL

            var requestData = new
            {
                prompt = "Hello, DeepSeek!", // 确保 prompt 是非空字符串
                max_tokens = 50 // 确保 max_tokens 是正整数且在允许范围内
            };

            string jsonRequest = JsonConvert.SerializeObject(requestData);
            var content = new StringContent(jsonRequest, Encoding.UTF8, "application/json");

            client.DefaultRequestHeaders.Clear();
            client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");

            try
            {
                // 打印请求数据调用API展示
                Console.WriteLine($"Request Data: {jsonRequest}");

                HttpResponseMessage response = await client.PostAsync(apiUrl, content);
                response.EnsureSuccessStatusCode();

                string jsonResponse = await response.Content.ReadAsStringAsync();
                var responseObject = JsonConvert.DeserializeObject<DeepSeekResponse>(jsonResponse);

                label1.Text = responseObject.choices[0].text;
            }
            catch (HttpRequestException ex)
            {
                // 打印错误信息
            }
        }

        public class DeepSeekResponse
        {
            public Choice[] choices { get; set; }
        }

        public class Choice
        {
            public string text { get; set; }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            var a = 2 > 1 && (3 > 2 || 1 > 2);
            MessageBox.Show(a+"");
        }
    }
}
